<template>
    <div class="app-container">
        <div class="block">
            <el-row>
                <el-col :span="24">
                    <el-select style="max-width:300px;margin-left: 10px;padding: 0px 15px;font-size: 12px;border-radius: 3px;" v-model="goodsCreatSelect" filterable placeholder="请选择">
                        <el-option v-for="item in goodsCreatList" :key="item.id" :label="item.nameAndAccount" :value="item.id"></el-option>
                    </el-select>
                    <el-button type="primary" size="mini" @click.native="writeOffButton">核销</el-button>
                    <span v-if="isShowString">&nbsp;&nbsp;&nbsp;核销金额：</span>
                    <span v-if="isShowString" style="color:red">{{ writeOffTotalString }}</span>
                    <span v-if="isShowString">&nbsp;&nbsp;&nbsp;销售金额：</span>
                    <span v-if="isShowString">{{ oldTotalString }}</span>
                </el-col>
            </el-row>
        </div>
        <el-table :data="list" v-loading="listLoading" element-loading-text="Loading" @selection-change="handleSelectionChange" border fit highlight-current-row>
            <el-table-column type="selection" width="55" :selectable="selectGoods"></el-table-column>
            <el-table-column label="商品名称">
                <template slot-scope="scope">{{ scope.row.goodsName }}</template>
            </el-table-column>
            <el-table-column label="货主" :formatter="formatCreat">
            </el-table-column>
            <el-table-column label="数量">
                <template slot-scope="scope">{{ scope.row.count }}</template>
            </el-table-column>
            <el-table-column label="销售单价(￥)">
                <template slot-scope="scope">{{ fmoney(scope.row.totalPrice/100,2) }}</template>
            </el-table-column>
            <el-table-column label="销售总价(￥)">
                <template slot-scope="scope">{{ fmoney(scope.row.totalPrice/100,2) }}</template>
            </el-table-column>
            <el-table-column label="核算比例">
                <template slot-scope="scope">{{ fmoney(scope.row.writeOffRate,2) }}%</template>
            </el-table-column>
            <el-table-column label="核算单价(￥)">
                <template slot-scope="scope">{{ fmoney(scope.row.price*scope.row.writeOffRate/10000,2) }}</template>
            </el-table-column>
            <el-table-column label="核算总价(￥)">
                <template slot-scope="scope">{{ fmoney(scope.row.totalPrice*scope.row.writeOffRate/10000,2) }}</template>
            </el-table-column>
        </el-table>

        <el-dialog :title="formTitle" :visible.sync="formVisible" width="70%">

            <el-form ref="form" :model="form" label-width="150px">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="商品名称:">
                            <div>{{ form.goodsName }}</div>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="单价:">
                            <div>￥{{ formPrice }}</div>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="数量:">
                            <div>{{ form.count }}</div>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="总价:">
                            <div>￥{{ formTotalPrice }}</div>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="核销比:">
                            <el-input-number type='number' :precision="2" :step="0.01" :min="0" :max="1" v-model.number="form.rate" minlength="1" @change="form.rate = oninput(form.rate)"></el-input-number>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="预计核销金额:">
                            <div>￥{{ willWriteOffNum }}</div>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-form-item>
                    <el-button type="primary" @click="updateWriteOffRateButton">{{ $t('button.submit') }}</el-button>
                    <el-button @click.native="formVisible = false">{{ $t('button.cancel') }}</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
    </div>
</template>

<script src="./unWriteOff.js"></script>

<style lang="scss" scoped>
@import "src/styles/common.scss";
</style>
